/**
 * 将图片 File 转为 base64 dataURL
 * 注意：返回值形如 ""
 */
export function fileToBase64(file: File): Promise<string> {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onload = () => resolve(String(reader.result || ''))
    reader.onerror = (err) => reject(err)
    reader.readAsDataURL(file)
  })
}

/**
 * 将 Blob 转为 base64 dataURL（若 Blob 没有类型，将按 application/octet-stream）
 */
export function blobToBase64(blob: Blob): Promise<string> {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onload = () => resolve(String(reader.result || ''))
    reader.onerror = (err) => reject(err)
    reader.readAsDataURL(blob)
  })
}
